Imports System.Xml
Imports System.Data.OleDb

Public NotInheritable Class PoserDownloadTrackerImporter
    Inherits BaseImporter

    Private Const ItemXpath As String = "/items/item"

    Private Const IdElement As String = "id"
    Private Const DescriptionElement As String = "description"
    Private Const VendorElement As String = "vendor"
    Private Const ArtistElement As String = "artist"
    Private Const BaseCharacterElement As String = "basecharacter"
    Private Const ObjectTypeElement As String = "objecttype"
    Private Const CategoryElement As String = "category"
    Private Const PlatformElement As String = "platform"
    Private Const ThemeElement As String = "theme"
    Private Const ProductIdElement As String = "productid"
    Private Const OrderNumberElement As String = "ordernumber"
    Private Const DatePurchasedElement As String = "datepurchased"
    Private Const PriceElement As String = "price"
    Private Const PaidElement As String = "paid"
    Private Const LicenseElement As String = "license"
    Private Const InstalledElement As String = "installed"
    Private Const FilenamesElement As String = "filenames"
    Private Const RuntimeLocationsElement As String = "runtimelocations"
    Private Const CommentsElement As String = "comments"
    Private Const ReadMeElement As String = "readme"

    Private Const PoserDownloadTrackerCode As String = "PDT"

    Public Overrides ReadOnly Property Source() As String
        Get
            Return PoserDownloadTrackerCode
        End Get
    End Property

    'Public Overrides ReadOnly Property ItemXPath() As String
    '    Get

    '    End Get
    'End Property

    Protected Overrides Sub AddItem(ByVal item As XmlElement)

        Dim id As Integer = -1
        Dim vendor As String = ""
        Dim artist As String = ""
        Dim baseCharacter As String = ""
        Dim description As String = ""
        Dim runtimes As String = ""
        Dim comments As String = ""
        Dim price, pricePaid As Single

        id = CType(CType(item.SelectSingleNode(IdElement), XmlElement).InnerText, Integer)
        vendor = CType(item.SelectSingleNode(VendorElement), XmlElement).InnerText
        artist = CType(item.SelectSingleNode(ArtistElement), XmlElement).InnerText
        baseCharacter = CType(item.SelectSingleNode(BaseCharacterElement), XmlElement).InnerText
        description = CType(item.SelectSingleNode(DescriptionElement), XmlElement).InnerText
        runtimes = CType(item.SelectSingleNode(RuntimeLocationsElement), XmlElement).InnerText
        comments = CType(item.SelectSingleNode(CommentsElement), XmlElement).InnerText
        price = CType(CType(item.SelectSingleNode(PriceElement), XmlElement).InnerText, Single)
        pricePaid = CType(CType(item.SelectSingleNode(ArtistElement), XmlElement).InnerText, Single)


    End Sub

    Public Overrides Sub Import(ByVal filePath As String)

        Dim dataToImport As New XmlDocument

        Try
            _conn.Open()

            dataToImport.Load(filePath)
            Dim items As XmlNodeList = dataToImport.SelectNodes(ItemXpath)
            For Each item As XmlNode In items
                AddItem(CType(item, XmlElement))
            Next

        Catch ex As XmlException
            MsgBox(ex.Message)
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            If _conn.State <> ConnectionState.Closed Then
                _conn.Close()
            End If
        End Try

    End Sub

End Class
